package com.ad.pet.app.shopcar.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.common.data.utils.glide.GlideUtil;
import com.ad.pet.models.remote.collect.Article;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by liuyixiang on 2019/10/31.
 */

public class ArticleAdapter extends BaseQuickAdapter<Article,BaseViewHolder>{
    private OnzanClickLinstenr mOnzanClickLinstenr;
    public ArticleAdapter( @Nullable List<Article> data) {
        super(R.layout.item_article_preview_layout, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final Article item) {
        ImageView ivHead = helper.getView(R.id.iv_head);
        TextView tv_name= helper.getView(R.id.tv_name);
        TextView tv_title= helper.getView(R.id.tv_title);
        TextView tv_date= helper.getView(R.id.tv_date);
        ImageView iv_image= helper.getView(R.id.iv_image);
        ImageView iv_zan = helper.getView(R.id.iv_zan);
        TextView tvZanNumber = helper.getView(R.id.tv_zan);
        TextView tvViewNumber = helper.getView(R.id.tv_view);
        TextView tv_say = helper.getView(R.id.tv_say);
        GlideUtil.loadCircle(mContext,item.getAvator(),ivHead);
        tv_name.setText(item.getAuthor());
        tv_title.setText(item.getTitle());
        tv_date.setText(item.getCreate_time());
        GlideUtil.load(mContext,item.getImage(),iv_image);
        tvZanNumber.setText(item.getUp_count());
        tvViewNumber.setText(item.getClick());
        tv_say.setText(item.getComment_count());
        helper.getView(R.id.linear_zan).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnzanClickLinstenr.onClick(helper.getLayoutPosition());
            }
        });

        iv_zan.setImageResource(item.isUp()?R.drawable.ic_zan:R.drawable.btn_zan);
        helper.getView(R.id.linear_share).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.goCommonWebView((Activity) mContext,item.getTitle(),item.getH5_url(),false,100);
            }
        });
    }

    public void setOnzanClickLinstenr(OnzanClickLinstenr onzanClickLinstenr) {
        this.mOnzanClickLinstenr = onzanClickLinstenr;
    }

    public interface OnzanClickLinstenr {
        void onClick(int position);

        void onComment(int position);
    }
}
